/*
 * @Author: EyeSklear 1814580085@qq.com
 * @Date: 2024-01-09 21:35:48
 * @LastEditors: EyeSklear 1814580085@qq.com
 * @LastEditTime: 2024-03-27 20:14:36
 * @FilePath: \Scene_Back\src\text\text.controller.ts
 * @Description:
 *
 * Copyright (c) 2024 by EyeSklear , All Rights Reserved.
 */
import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  Req,
} from '@nestjs/common';
import { TextService } from './text.service';
import { CreateTextDto } from './dto/create-text.dto';
import { UpdateTextDto } from './dto/update-text.dto';
import { Request } from 'express';

@Controller('text')
export class TextController {
  constructor(private readonly textService: TextService) {}

  @Post('createTextItem')
  createTextItem(
    @Body() createTextDto: CreateTextDto,
    @Req() request: Request,
  ) {
    const user = request.user;
    createTextDto.creator = (user as any).email;
    return this.textService.create(createTextDto);
  }

  @Get('findAll')
  findAll() {
    return this.textService.findAll();
  }

  @Get('findUser/:creator')
  findUser(@Param('creator') creator: string) {
    return this.textService.findUser(creator);
  }

  @Get('findOne/:id')
  findOne(@Param('id') id: string) {
    return this.textService.findOne(id);
  }

  @Patch('updateTextItem/:id')
  updateTextItem(
    @Param('id') id: string,
    @Body() updateTextDto: UpdateTextDto,
  ) {
    return this.textService.update(id, updateTextDto);
  }

  @Delete('removeTextItem/:id')
  removeTextItem(@Param('id') id: string) {
    return this.textService.remove(id);
  }
}
